

<div class="layui-form" lay-filter="layuiadmin-form-teacher" style="padding: 20px 30px 0 0;">
    <!-- 所属部门（带下拉选择框，支持切换其他部门） -->
    <div class="layui-form-item">
        <label class="layui-form-label">所属部门</label>
        <div class="layui-input-inline">
            <script type="text/html" template>
                <!-- 隐藏域存储当前教师的部门ID，用于回显默认选中项 -->
                <input type="hidden" name="pidh" id="pidh" value="{{ d.params.departmentId || '' }}" />
                <!-- 下拉选择框，支持选择其他部门 -->
                <select name="pdnames" id="pdnames" lay-verify="required">
                    <option value="" selected>请选择所属部门</option>
                </select>
            </script>
        </div>
    </div>

    <!-- 教师姓名 -->
    <div class="layui-form-item">
        <label class="layui-form-label">教师姓名</label>
        <div class="layui-input-inline">
            <script type="text/html" template>
                <input type="text" name="cname" value="{{ d.params.teacherName || '' }}" lay-verify="required"
                       placeholder="请输入教师姓名" autocomplete="off" class="layui-input">
                <input type="hidden" name="cid" value="{{ d.params.teacherId || '' }}"
                       autocomplete="off" class="layui-input">
            </script>
        </div>
    </div>

    <!-- 教师编号 -->
    <div class="layui-form-item">
        <label class="layui-form-label">教师编号</label>
        <div class="layui-input-inline">
            <script type="text/html" template>
                <input type="text" name="tnum" value="{{ d.params.teacherNum || '' }}" lay-verify="required"
                       placeholder="请输入教师编号" autocomplete="off" class="layui-input">
            </script>
        </div>
    </div>

    <!-- 联系电话 -->
    <div class="layui-form-item">
        <label class="layui-form-label">联系电话</label>
        <div class="layui-input-inline">
            <script type="text/html" template>
                <input type="text" name="tphone" value="{{ d.params.teacherPhone || '' }}"
                       placeholder="请输入联系电话" autocomplete="off" class="layui-input">
            </script>
        </div>
    </div>

    <!-- 性别 -->
    <div class="layui-form-item">
        <label class="layui-form-label">性别</label>
        <div class="layui-input-inline">
            <script type="text/html" template>
                <select name="tgender" id="tgender">
                    <option value="" selected>请选择性别</option>
                    <option value="男" {{ d.params.teacherGender === '男' ? 'selected' : '' }}>男</option>
                    <option value="女" {{ d.params.teacherGender === '女' ? 'selected' : '' }}>女</option>
                </select>
            </script>
        </div>
    </div>

    <!-- 状态 -->
    <div class="layui-form-item" lay-filter="cflag">
        <label class="layui-form-label">状态</label>
        <div class="layui-input-inline">
            <script type="text/html" template>
                <input type="radio" name="cflag" value="0" title="启用" {{ d.params.teacherFlag === '启用' ? 'checked' : '' }}>
                <input type="radio" name="cflag" value="1" title="禁用" {{ d.params.teacherFlag === '禁用' ? 'checked' : '' }}>
            </script>
        </div>
    </div>

    <!-- 提交按钮 -->
    <div class="layui-form-item">
        <label class="layui-form-label"></label>
        <div class="layui-input-inline">
            <input type="button" lay-submit lay-filter="LAY-modify" value="确认" class="layui-btn">
        </div>
    </div>
</div>

<script>
layui.use(['admin', 'form'], function(){
  var $ = layui.$
  ,form = layui.form;
  
});
layui.use(['form', 'layer'], function() {
    var $ = layui.$;
    var form = layui.form;
    var layer = layui.layer;

    // 加载所有部门数据到下拉选择框
    $.ajax({
        url: '/getDeptsServlet',
        dataType: 'json',
        type: 'post',
        timeout: 10000,
        success: function(data) {
            // 遍历部门数据，添加到下拉框
            $.each(data.data, function(index, dept) {
                $('#pdnames').append(new Option(dept.departmentName, dept.departmentId));
            });
            // 回显当前教师所属部门（从隐藏域获取值并选中）
            $('#pdnames').val($('#pidh').val());
            // 重新渲染下拉框，确保选中状态生效
            form.render('select');
        },
        error: function() {
            layer.msg('部门数据加载失败', {icon: 2});
        }
    });

});
</script>